package binaryTree.re12_04;

import binaryTree.basic.TreeNode;

import javax.sound.sampled.Line;
import java.util.LinkedList;

public class CengXu {

    public   void  cengxu(TreeNode  root){
        if (root==null){
            return;
        }
        LinkedList<TreeNode> queue= new LinkedList<>();
        queue.addLast(root);
        while (queue.size()>0){
            int size = queue.size();
            while (size>0){
                TreeNode cur = queue.pollFirst();
                System.out.println(cur.val);
                size--;
                if (cur.left!=null){
                    queue.addLast(cur.left);
                }
                if (cur.right!=null){
                    queue.addLast(cur.right);
                }
            }
        }
    }

    public static void main(String[] args) {
        CengXu cengXu = new CengXu();
        TreeNode treeNode1 = new TreeNode(1);
        TreeNode treeNode2 = new TreeNode(2);
        TreeNode treeNode3 = new TreeNode(3);
        TreeNode treeNode4 = new TreeNode(4);
        TreeNode treeNode5 = new TreeNode(5);
        TreeNode treeNode6 = new TreeNode(6);
        TreeNode treeNode7 = new TreeNode(7);
//        TreeNode treeNode8 = new TreeNode(2);
//        TreeNode treeNode9 = new TreeNode(1);
        treeNode1.left=treeNode2;
        treeNode1.right=treeNode3;
        treeNode2.left=treeNode4;
        treeNode2.right=treeNode5;
        treeNode3.left=treeNode6;
        treeNode3.right=treeNode7;
        cengXu.cengxu(treeNode1);

    }

}
